﻿var id, url = "../TR/QuestionnaireSend.aspx",
    entity = "1";
var getUrl = "http://" + this.location.host + "/EditWidows/";
var src = "";
if (typeof ($) != 'undefined') {
    $(document).ready(function () {
        $("button").click(function (event) {
            if (event.target.id.indexOf("btn") > -1) {
                id = event.target.id;
                var name = event.target.name;
                var entityName;
                //debugger;
                switch (name.toLowerCase()) {
                    case "a": //课前辅导
                        //entityName = "TrActivityCourse";
                        entityName = "V_TrActivityCourseExpectation";
                        postUrl(entityName, "", "TrActivityCourseID", "CourseName");
                        break;
                    case "b": // 培训课程
                        entityName = "TrCourse";
                        postUrl(entityName, "", "TrCourseID", "CourseName");
                        break;
                    case "c":  //培训客户
                        entityName = "V_TrCustomer";
                        postUrl(entityName, "", "TrCustomerId", "CustomerName");
                        break;
                    case "d":
                        //部门
                        //内部客户
                        //entityName = "DatDepartment";
                        //debugger
                        entityName = "V_DatDepartment";
                        postUrl(entityName, "", "DeptID", "DeptName");
                        break;
                    case "e": //职员
                        entityName = "DatEmployee";
                        postUrl(entityName, "", "EmpID", "Name");
                        break;
                    case "f": //后台所有客户
                        entityName = "V_CrmCustomerInfoSale";
                        postUrl(entityName, "", "ID", "CustomerName");
                        break;
                    case "fv": //价值业绩--缴款单已经结业的客户
                        entityName = "V_CrmCustomerInfoSale";
                        condition = "crmvalue";
                        postUrl(entityName, condition, "ID", "CustomerName");
                        break;
                    case "fq":
                        entityName = "V_CrmCustomerInfoSale";
                        condition = "crmqichu";
                        postUrl(entityName, condition, "ID", "CustomerName");
                        break;
                    case "g": //业绩归属
                        entityName = "DatDepartment";
                        document.getElementById("EditUIWindow2").src = getUrl + "YUITree.aspx?r=" + Math.random() + "&entity=" + entityName + "&masterPara=DatDepartment|DeptName|DeptID|ParentID|DeptPath|False";
                        ShowDialog2(getSelected, id);
                        break;
                    case "h":
                        //选择客户总监
                        entityName = "V_UserEmp";
                        parent.document.getElementById("EditUIWindow1").src = getUrl + "ChooseList.aspx?r=" + Math.random() + "&entity=" + entityName + "&condition=" + decodeURI(condition);
                        parent.ShowDialog(getSelected, id);
                        break;
                    case "i":
                        //选择部门
                        entityName = "DatDepartment";
                        parent.document.getElementById("EditUIWindow1").src = getUrl + "YUITree.aspx?r=" + Math.random() + "&entity=" + entityName + "&masterPara=DatDepartment|DeptName|DeptID|ParentID|DeptPath|False";
                        parent.ShowDialog(getSelected, id);
                        break;
                    case "j":
                        //缴款单客户选择
                        entityName = "V_CrmPayByCid";
                        postUrl(entityName, "(CustomeerMgr='" + addUser + "' or LectorUser='" + addUser + "')", "ID", "Code");
                        break;
                    case "k":  //产品规划
                        entityName = "CrmProductLayout";
                        postUrl(entityName, "&order=BeginDate desc", "ID", "CourseLayoutName");
                        break;
                    case "kk":  //产品规划--价值业绩
                        entityName = "CrmProductLayout";
                        postUrl(entityName, "&order=BeginDate desc", "ID", "CourseLayoutNames");
                        break;
                    case "l": //客户经理独立开发的客户
                        entityName = "V_CrmCustomerInfoSale";
                        condition = "crmlinkman";
                        postUrl(entityName, condition, "ID", "CustomerName");
                        break;
                    case "m":
                        //客户选择                        
                        entityName = "V_CrmCustomerShow";
                        postUrl(entityName, "", "ID", "CustomerName");
                        break;
                    case "mz":
                        //客户选择  --短信分组
                        entityName = "V_CrmCustomerShowM";
                        src = getUrl + "ChooseList.aspx?r=" + Math.random() + "&entity=" + entityName + "&kid=DecisionTel&kname=CustomerName" + "&condition=" + decodeURI(condition);
                        ShowDialog(getSelected, id, src);
                        break;
                    case "n":
                        //流程授权用户选择
                        entityName = "V_UserEmp";
                        postUrl(entityName, "", "LoginName", "Name");
                        break;
                    case "o": //大课交付单选中
                        entityName = "V_DeliverOrderProduct";
                        postUrl(entityName, "", "ID", "OrderCode");
                        break;
                    case "p":  //职位
                        entityName = "DatPost";
                        src = getUrl + "YUITree.aspx?r=" + Math.random() + "&entity=" + entityName + "&masterPara=DatPost|PostName|PostID|ParentID|DeptID|False";
                        parent.ShowDialog(getSelected, id, src)
                        //postUrl(entityName, "", "PositionID", "PositionName");
                        break;
                    case "pp":
                        entityName = "V_CrmProductLayoutPrint";
                        condition = "UserId='" + userid + "'";
                        postUrl(entityName, condition, "ID", "CourseLayoutName");
                        break;
                    case "q": //订单
                        entityName = "V_CrmCustomerOrder";
                        postUrl(entityName, "", "ID", "Code");
                        break;
                    case "r":
                        var condition = "";
                        entityName = "V_UserEmp";  //选择外部用户
                        src = getUrl + "ChooseList.aspx?r=" + Math.random() + "&entity=" + entityName + "&kid=UserIDs&kname=Name" + "&condition=" + decodeURI(condition);
                        ShowDialog1(getSelected, id, src);
                        break;
                    case "rv":
                        var condition = "";
                        entityName = "V_CrmValuePay";  //选择外部用户
                        src = getUrl + "ChooseList.aspx?r=" + Math.random() + "&entity=" + entityName + "&kid=IDs&kname=Caption" + "&condition=" + decodeURI(condition);
                        ShowDialog1(getSelected, id, src);
                        break;
                    case "mes":
                        var condition = "";
                        var opt = document.getElementById("selectOption").value;
                        var entityName = "";
                        if (opt == "0") {
                            entityName = "V_UserMessage";  //消息中心选择手机号
                            src = getUrl + "ChooseList.aspx?r=" + Math.random() + "&entity=" + entityName + "&kid=UserIDs&kname=Mobile" + "&condition=" + decodeURI(condition);
                        }
                        else if (opt == "1") {
                            entityName = "V_CrmCustomerShowM";
                            src = getUrl + "ChooseList.aspx?r=" + Math.random() + "&entity=" + entityName + "&kid=UserIDs&kname=Mobile" + "&condition=" + decodeURI(condition);
                        }
                        else if (opt == "2") {
                            condition = "AddUser='" + addUser + "'";
                            entityName = "V_MQOrgType";
                            src = getUrl + "ChooseList.aspx?r=" + Math.random() + "&entity=" + entityName + "&kid=otid&kname=otname" + "&condition=" + decodeURI(condition);
                        }
                        else if (opt == "3") {
                            entityName = "V_MQOrgBody";
                            src = getUrl + "ChooseList.aspx?r=" + Math.random() + "&entity=" + entityName + "&kid=obids&kname=Mobile" + "&condition=" + decodeURI(condition);
                        }
                        else if (opt == "4") {
                            entityName = "V_CrmCustomerInfoM";
                            src = getUrl + "ChooseList.aspx?r=" + Math.random() + "&entity=" + entityName + "&kid=UserIDs&kname=Mobile" + "&condition=" + decodeURI(condition);
                        }
                        ShowDialog1(getSelected, id, src);
                        break;
                    case "mq4":
                        entityName = "V_UserMq400";
                        src = getUrl + "ChooseList.aspx?r=" + Math.random() + "&entity=" + entityName + "&kid=UserIDs&kname=Mobile" + "&condition=" + decodeURI(condition);
                        ShowDialog1(getSelected, id, src);
                        break;
                    case "mzx":
                        var condition = "";
                        var opt = document.getElementById("selectOption").value;
                        var entityName = "";
                        if (opt == "0") {
                            entityName = "V_UserMessage";  //消息中心选择手机号
                            src = getUrl + "ChooseList.aspx?r=" + Math.random() + "&entity=" + entityName + "&kid=UserIDs&kname=Name" + "&condition=" + decodeURI(condition);
                        }
                        else if (opt == "1") {
                            entityName = "V_CrmCustomerShowM";
                            src = getUrl + "ChooseList.aspx?r=" + Math.random() + "&entity=" + entityName + "&kid=UserIDs&kname=Name" + "&condition=" + decodeURI(condition);
                        }
                        ShowDialog1(getSelected, id, src);
                        break;
                    case "mqo":
                        var condition = "AddUser='" + addUser + "'";
                        var entityName = "V_MQModel";
                        src = getUrl + "ChooseList.aspx?r=" + Math.random() + "&entity=" + entityName + "&kid=mqmid&kname=Mcontent" + "&condition=" + decodeURI(condition);
                        ShowDialog1(getSelected, id, src);
                        break;
                    case "mmss":
                        var condition = "AddUser='" + addUser + "'";
                        var entityName = "V_MmsMessage";
                        src = getUrl + "ChooseList.aspx?r=" + Math.random() + "&entity=" + entityName + "&kid=mmid&kname=mtitle" + "&condition=" + decodeURI(condition);
                        ShowDialog1(getSelected, id, src);
                        break;
                    case "s": //部门
                        entityName = "DatDepartment";
                        //                        if (typeof (editlist) == "undefined") {
                        //                            src = getUrl + "YUITree.aspx?r=" + Math.random() + "&entity=" + entityName + "&masterPara=DatDepartment|DeptName|DeptID|ParentID|DeptPath|True";
                        //                            parent.ShowDialog(getSelected, id, src)
                        //                        } else {
                        //                            src = getUrl + "YUITree.aspx?r=" + Math.random() + "&entity=" + entityName + "&masterPara=DatDepartment|DeptName|DeptID|ParentID|DeptPath|True";
                        //                            ShowDialog(getSelected, id, src)
                        //                        }
                        src = getUrl + "YUITree.aspx?r=" + Math.random() + "&entity=" + entityName + "&masterPara=DatDepartment|DeptName|DeptID|ParentID|DeptPath|False";
                        parent.ShowDialog(getSelected, id, src)
                        break;
                    case "bba":
                        var condition = "";
                        var opt;
                        var index = document.getElementById("hdfindex");
                        if (index== null) {
                            opt = document.getElementById("DataList1_ddlfanwei").value;
                        }
                        else {
                            opt = document.getElementById("DataList1_ddlotype_" + index.value).value;
                        }
                        if (opt == "" || opt == null) {
                            alert("请选择[申请范围]");
                            return;
                        }
                        var entityName = "";
                        if (opt == "1") {
                            condition = "";
                            entityName = "V_UserEmp";
                            src = getUrl + "ChooseList.aspx?r=" + Math.random() + "&entity=" + entityName + "&kid=UserIDs&kname=Name" + "&condition=" + decodeURI(condition);
                            ShowDialog1(getSelected, id, src);
                        }
                        else if (opt == "2") {
                            condition = "";
                            entityName = "V_UserEmp";
                            src = getUrl + "YUITree.aspx?r=" + Math.random() + "&entity=" + entityName + "&masterPara=DatDepartment|DeptName|DeptID|ParentID|DeptPath|False";
                            ShowDialog1(getSelected, id, src);
                        }
                        else if (opt == "3") {
                            entityName = "SysRole";
                            condition = " ";
                            src = getUrl + "ChooseList.aspx?r=" + Math.random() + "&entity=" + entityName + "&kid=RoleID&kname=RoleName" + "&condition=" + decodeURI(condition);
                            //src = "../EditWidows/YUIMenuList.aspx?conditonid=" + condition + "&masterentity=SysUserRole&masterPara=SysRole|RoleName|RoleID|True";
                            ShowDialog1(getSelected, id, src);
                        }
                        break;
                    case "t":
                        entityName = "DatUser";  //选择外部用户
                        var recordIDs = parent.mDataTable.getSelectedRows()[0];
                        records = parent.myDataTable.getRecord(recordIDs);
                        var t = records.getData("TrCustomerID");
                        postUrl(entityName, " CustomerID='" + t + "'", "UserID", "UName");
                        break;
                    case "u":    //选择用户
                        entityName = "DatUser";
                        postUrl(entityName, " isOutSite=0 and IsExpire=0", "UserID", "UName");
                        break;
                    case "v":
                        //选择客户经理
                        entityName = "V_UserEmp";
                        postUrl(entityName, "", "UserID", "Name");
                        break;
                    case "w":
                        //外部客户
                        entityName = "DatDepartment";
                        postUrl(entityName, "IsOutDepartment=1", "DeptID", "DeptName");
                        break;
                    case "x":
                        //缴款单用户选择
                        entityName = "V_UserEmp";
                        document.getElementById("EditUIWindow3").src = getUrl + "ChooseList.aspx?r=" + Math.random() + "&kid=UserID&kname=Name&entity=" + entityName + "&condition=" + decodeURI(" isOutSite=0");
                        ShowDialog3(getSelected, id);
                        break;
                    case "x1":
                        //缴款单用户选择
                        entityName = "V_UserEmp";
                        parent.document.getElementById("EditUIWindow3").src = getUrl + "ChooseList.aspx?r=" + Math.random() + "&kid=UserID&kname=Name&entity=" + entityName + "&condition=" + decodeURI(" isOutSite=0");
                        parent.ShowDialog3(getSelected, id);
                        break;
                    //客户现场选择                                                                                               
                    case "y":
                        entityName = "V_CrmLiveCustomer";
                        condition = "id='" + StrProductId + "'";
                        postUrl(entityName, condition, "CustomerId", "CustomerName");
                        break;
                    case "z":
                        //用户选择
                        entityName = "V_UserEmp";
                        condition = decodeURI(" isOutSite=0 and IsExpire=0");
                        postUrl(entityName, condition, "UserID", "Name");
                        break;
                    case "zterm":
                        //英才期数选择
                        entityName = "V_CrmDeliverHrTerm";
                        condition = decodeURI(" IsClose='0'");
                        postUrl(entityName, condition + "&order=StartTime", "ID", "TermName");
                        break;
                    case "emp": //选择职员
                        //debugger
                        //用户选择
                        entityName = "V_hrEmployee";
                        condition = "";
                        postUrl(entityName, condition, "ID", "CName");
                        break;
                    case "0":  //客户关系列表
                        entityName = "V_CrmCustomerRelation";
                        condition = "";
                        postUrl(entityName, condition, "ID", "CustomerName");
                        break;
                    case "-1":  //大课交付申请单选择订单
                        entityName = "V_CrmCustomerInfoDeliver";
                        condition = "1=1";
                        postUrl(entityName, condition, "ID", "Code");
                        break;
                    case "1":  //大课交付申请单选择订单
                        entityName = "V_CrmCustomerInfoDeliver";
                        condition = "CustomeerMgr='" + addUser + "' and PhraseID='9b1639ba-d3fd-4f1c-bab2-12fedbc8b30d'";
                        postUrl(entityName, condition, "ID", "Code");
                        break;
                    case "2":  //项目交付申请单选择订单
                        entityName = "V_CrmCustomerInfoDeliver";
                        condition = "CustomeerMgr='" + addUser + "' and PhraseID='3AEDE3F6-1915-48D5-AFB2-C9380DB26813'";
                        postUrl(entityName, condition, "ID", "Code");
                        break;
                    case "3":  //内训交付申请单选择订单             
                        entityName = "V_CrmCustomerInfoDeliver";
                        //condition = "PhraseID='9b1639ba-d3fd-4f1c-bab2-12fedbc8b30d'";
                        condition = "CustomeerMgr='" + addUser + "' and PhraseID='CED37B58-A821-40F6-A6D6-2DA9035DDDF5' and ID in(select distinct orderid from V_DeliverOrderProduct where productid in (select Productid from CrmProduct where TypeId='CED37B58-A821-40F6-A6D6-2DA9035DDDF5')) ";
                        postUrl(entityName, condition, "ID", "Code");
                        break;
                    case "4":  //内训交付申请单选择订单             
                        //condition = "PhraseID='9b1639ba-d3fd-4f1c-bab2-12fedbc8b30d'";
                        //condition = "DliverState='8A41F2EF-989F-4871-BBE9-91CDFF4235CA' and productid in (select Productid from CrmProduct where TypeId='CED37B58-A821-40F6-A6D6-2DA9035DDDF5') ";
                        condition = "productid in (select Productid from CrmProduct where TypeId='CED37B58-A821-40F6-A6D6-2DA9035DDDF5') ";

                        entityName = "V_DeliverOrderProduct";
                        postUrl(entityName, condition, "ID", "OrderCode");
                        break;
                    case "20":  //英才交付申请单选择订单
                        entityName = "V_CrmCustomerInfoDeliverHR";
                        condition = "CustomeerMgr='" + addUser + "' and (StateID='EDA4FAA9-8544-494C-BF1C-02662E1078A6' or StateID='AF73673F-9FEC-4D14-ACFD-B0FCE08D6FFA') and (Productid in('B387B0E6-1AB8-4C93-96AA-814CC2D12FB3','A1A9B420-6F24-4EE1-97A7-82C0A37C48A0','0A9AAC1A-A18F-4D00-9D3E-DEB74BBF1E22') or PhraseID='98FE5705-0780-4BF4-923C-F853E8FDC916')";
                        //condition = "CustomeerMgr='" + addUser + "' and (Productid='B387B0E6-1AB8-4C93-96AA-814CC2D12FB3' or Productid='A1A9B420-6F24-4EE1-97A7-82C0A37C48A0'  or Productid='0A9AAC1A-A18F-4D00-9D3E-DEB74BBF1E22'  )";
                        postUrl(entityName, condition, "ID", "Code");
                        break;
                    case "5":
                        //debugger;
                        var condition = "";
                        entityName = "V_UserEmp";  //选择多人    ,返回多个用户名 如zhangsan,lisi,wangwu
                        src = getUrl + "ChooseList.aspx?r=" + Math.random() + "&entity=" + entityName + "&kid=LoginNames&kname=Name" + "&condition=" + decodeURI(condition);
                        if (parent.ShowDialog1 != undefined) {
                            parent.ShowDialog1(getSelected, id, src);
                        }
                        else {
                            ShowDialog1(getSelected, id, src);
                        }
                        break;
                    case "6":
                        //单用户选择 ,返回单个用户名 如zhangsan
                        entityName = "V_UserEmp";
                        condition = decodeURI(" isOutSite=0 and IsExpire=0");
                        postUrl(entityName, condition, "LoginName", "Name");
                        break;
                    case "7":
                        //业绩归属 (选择分公司)
                        entityName = "DatDepartment";
                        condition = "deptType=1";
                        document.getElementById("EditUIWindow2").src = getUrl + "YUIMenuList.aspx?&condition=" + decodeURI(condition) + "&masterentity=" + entityName + "&masterPara=DatDepartment|DeptName|DeptID|False";
                        ShowDialog2(getSelected, id);
                        break;
                    case "8": //客户切换(公海-客户信息)
                        entityName = "V_CrmCustomerShow";
                        document.getElementById("EditUIWindow1").src = getUrl + "SubjectList.aspx?entity=" + entityName + "&order=AddTime";
                        ShowDialog2(getSelected, id);
                        break;
                    case "9": //客户切换(客户信息-公海)
                        entityName = "V_CrmCustomerInfoSale";
                        document.getElementById("EditUIWindow1").src = getUrl + "SubjectList.aspx?entity=" + entityName + "&order=AddTime";
                        ShowDialog2(getSelected, id);
                        break;
                    case "10": //选择客户区域
                        entityName = "V_CrmUserArea";
                        condition = decodeURI(" UserID='" + userid + "'");
                        postUrl(entityName, condition, "DeptID", "DeptName");
                        break;
                    case "100": //选择客户区域
                        entityName = "V_CrmUserAreaAll";
                        condition = decodeURI(" IsVirtualDepartment=1 ");
                        postUrl(entityName, condition, "DeptID", "DeptName");
                        break;
                    case "11": //选择行业
                        entityName = "DatPhraseDetail";
                        condition = decodeURI(" ClassID='1E2882F8-7C36-4684-920F-6452BA2015A8'");
                        postUrl(entityName, condition, "PhraseID", "PhraseText");
                        break;
                    case "12":
                        entityName = entity;
                        src = getUrl + "YUITree.aspx?r=" + Math.random() + "&entity=" + entityName + "&masterPara=CrmSubjectManager|SubjectName|ID|SuperiorSubjectID|SubjectPath|False";
                        parent.ShowDialog(getSelectedAndDatposinit, id, src)
                        break;
                    case "13":  //发票申请单选择订单
                        //debugger
                        entityName = "V_CrmCustomerInfoOrder";
                        condition = "1=1";
                        src = getUrl + "ChooseList.aspx?r=" + Math.random() + "&kid=ID&kname=Code&entity=" + entityName + "&condition=" + decodeURI(condition) + "";
                        parent.ShowDialog(getSelected, id, src);
                        break;
                    case "14":  //赠送订单选择关联订单
                        //debugger
                        entityName = "V_CrmCustomerInfoOrders";
                        var cId = $("#CustomerID").val();
                        if (cId == "")
                            cId = "00000000-0000-0000-0000-000000000000";
                        condition = "Code not like '%DZ%' and CustomerId='" + cId + "'";
                        postUrl(entityName, encodeURI(condition), "ID", "Code");
                        break;
                    case "js":
                        entityName = "V_CrmChoseTeacher";
                        condition = "1=1";
                        postUrl(entityName, condition, "UserID", "CName");
                        break;
                    case "qd":
                        //客户选择
                        entityName = "V_CrmCustomerShow";
                        condition = "qudao";
                        postUrl(entityName, condition, "ID", "CustomerName");
                        break;
                    case "tk":  //退款申请单选择订单
                        entityName = "V_CrmCustomerInfoOrderTK";
                        condition = decodeURI(" (AddUser='" + addUser + "' or CustomeerMgr='" + addUser + "') and ProductResignMoney>0 and TypeID <> '5e50217a-414e-46d5-89bc-348ad0145ffc' ");
                        src = getUrl + "ChooseList.aspx?r=" + Math.random() + "&kid=ID&kname=Code&entity=" + entityName + "&condition=" + decodeURI(condition) + "";
                        parent.ShowDialog(getSelected, id, src);
                        break;
                    case "pos": //调岗控件            
                        src = getUrl + "YUITree.aspx?r=" + Math.random() + "&entity=" + entityName + "&masterPara=DatDepartment|DeptName|DeptID|ParentID|DeptPath|False";
                        parent.ShowDialog(getSelectedAndDatposinit, id, src)
                        break;
                    case "dep": //跨门部门控件
                        entityName = "DatDepartment";
                        //                        if (typeof (editlist) == "undefined") {
                        //                            src = getUrl + "YUITree.aspx?r=" + Math.random() + "&entity=" + entityName + "&masterPara=DatDepartment|DeptName|DeptID|ParentID|DeptPath|False";
                        //                            parent.ShowDialog(getSelectedTRFDept, id, src)
                        //                        } else {
                        //                            src = getUrl + "YUITree.aspx?r=" + Math.random() + "&entity=" + entityName + "&masterPara=DatDepartment|DeptName|DeptID|ParentID|DeptPath|True";
                        //                            ShowDialog(getSelectedTRFDept, id, src)
                        //                        }
                        src = getUrl + "YUITree.aspx?r=" + Math.random() + "&entity=" + entityName + "&masterPara=DatDepartment|DeptName|DeptID|ParentID|DeptPath|False";
                        parent.ShowDialog(getSelectedTRFDept, id, src)
                        break;
                    case "muldep": //多部门选择
                        entityName = "DatDepartment";
                        document.getElementById("EditUIWindow2").src = getUrl + "YUITree.aspx?r=" + Math.random() + "&entity=" + entityName + "&masterPara=DatDepartment|DeptName|DeptID|ParentID|DeptPath|true";
                        ShowDialog2(getSelected, id);
                        break;
                    case "workflowfell": //

                        entityName = "V_UserEmp";
                        condition = decodeURI(" isOutSite=0 and IsExpire=0");
                        postUrl1(entityName, condition, "LoginName", "Name");
                        break;
                    case "customerbylayoutid":
                        entityName = "V_CrmCustomerInfoProductLayout";
                        condition = "ProductLayoutID = '" + productLayoutID + "'";
                        postUrlInRole(entityName, condition, "ID", "CustomerName", functionId);
                        break;
                    case "deliverorderid":
                        entityName = "V_CrmCustomerOrderDeliverStudent";
                        condition = $("#layoutID").val() == "" ? "" : "ProductLayoutID = '" + $("#layoutID").val() + "'";
                        src = getUrl + "ChooseList.aspx?r=" + Math.random() + "&entity=" + entityName + "&kid=ID&kname=Code&condition=" + decodeURI(condition) + "";
                        ShowDialog(getSelected, id, src);
                        break;
                    default:
                        break;

                }
                /*if (t == "M") {
                if (typeof (editlist) == "undefined") {
                parent.document.getElementById("EditUIWindow1").src = "../EditWidows/YUITree.aspx?r=" + Math.random() + "&entity=" + entityName + "&masterPara=DatDepartment|DeptName|DeptID|ParentID|DeptPath|True";
                parent.ShowDialog(getSelected, id)
                } else {
                document.getElementById("EditUIWindow1").src = "../EditWidows/YUITree.aspx?r=" + Math.random() + "&entity=" + entityName + "&masterPara=DatDepartment|DeptName|DeptID|ParentID|DeptPath|True";
                ShowDialog(getSelected, id)
                }
                }*/
                //debugger;
                if (id.indexOf("btnDeptIds") > -1) {
                    //alert("DeptIds:" + $("#DeptIds").val())
                    entityName = "DatDepartment";
                    var src = "";
                    if (typeof (editlist) == "undefined") {
                        src = getUrl + "YUITree.aspx?r=" + Math.random() + "&entity=" + entityName + "&masterPara=DatDepartment|DeptName|DeptID|ParentID|DeptPath|True&IsHighlightUpDown=false&IsExpandAll=true&CtrlID=";
                        parent.ShowDialog(getSelected, id, src)
                    }
                    else {
                        src = getUrl + "YUITree.aspx?r=" + Math.random() + "&entity=" + entityName + "&masterPara=DatDepartment|DeptName|DeptID|ParentID|DeptPath|True&IsHighlightUpDown=false&IsExpandAll=true";
                        ShowDialog(getSelected, id, src)
                        setTimeout(getCheckedNodes, 200);
                    }

                }
            }
        });
    });

    //得到已经选择的部门
    var getCheckedNodes = function () {
        //debugger;
        var editwindow = parent.document.getElementById("EditUIWindow1");
        if (editwindow) {
            editwindow.contentWindow.checkSelectedNode($("#DeptIds").val());
        }
    }

    //提交传值 参数说明:  entityName-实体名称 condition-自定义条件 kid-值名称 kname-显示字段 
    function postUrl1(entityName, condition, kid, kname) {
        //debugger;
        if (typeof (parent.ShowDialog) == "undefined") {
            src = "../BasePages/WorkFlowOrder.aspx?r=" + Math.random() + "&entity=" + entityName + "&kid=" + kid + "&kname=" + kname + "&condition=" + decodeURI(condition);
            ShowDialog(getSelected, id, src);
        }
        else {
            src = "../BasePages/WorkFlowOrder.aspx?r=" + Math.random() + "&entity=" + entityName + "&kid=" + kid + "&kname=" + kname + "&condition=" + decodeURI(condition);
            parent.ShowDialog(getSelected, id, src);
        }
    }
    //提交传值 参数说明:  entityName-实体名称 condition-自定义条件 kid-值名称 kname-显示字段 
    function postUrl(entityName, condition, kid, kname) {
        //debugger;
        //{本表单有当前方法，直接调用当前表单方法，否则查找父级，以及父级的父级. 2014-08-19 wangjihui 394594745@qq.com}
        if (typeof (ShowDialog) == "function") {
            src = getUrl + "ChooseList.aspx?r=" + Math.random() + "&entity=" + entityName + "&kid=" + kid + "&kname=" + kname + "&condition=" + decodeURI(condition);
            ShowDialog(getSelected, id, src);
            return;
        }

        //原来代码
        if (typeof (parent.ShowDialog) == "undefined") {
            if (typeof (ShowDialog) == "undefined") {
                src = getUrl + "ChooseList.aspx?r=" + Math.random() + "&entity=" + entityName + "&kid=" + kid + "&kname=" + kname + "&condition=" + decodeURI(condition);
                parent.parent.ShowDialog(getSelected, id, src);
            }
            else {
                src = getUrl + "ChooseList.aspx?r=" + Math.random() + "&entity=" + entityName + "&kid=" + kid + "&kname=" + kname + "&condition=" + decodeURI(condition);
                ShowDialog(getSelected, id, src);
            }
        }
        else {
            src = getUrl + "ChooseList.aspx?r=" + Math.random() + "&entity=" + entityName + "&kid=" + kid + "&kname=" + kname + "&condition=" + decodeURI(condition);
            parent.ShowDialog(getSelected, id, src);
        }
    }

    //提交传值 参数说明:  entityName-实体名称 condition-自定义条件 kid-值名称 kname-显示字段
    function postUrlInRole(entityName, condition, kid, kname, fId) {
        src = getUrl + "ChooseList.aspx?r=" + Math.random() + "&entity=" + entityName + "&kid=" + kid + "&kname=" + kname + "&condition=" + decodeURI(condition) + "&functionId=" + fId + "";
        ShowDialog(getSelected, id, src);
    }

    var list = new Array();
    function getSelected(v, t) {
        //debugger;
        //alert("v:" +v+" t:"+t);
        if (v != "") {
            if (typeof (v) == "object") {
                var str = v.join(',');
                $("#" + id.replace(/btn/g, "")).val(str);
                //YAHOO.util.Connect.asyncRequest('POST', url + "?flag=1&testjson=" + str + "&entity=" + entity, callback);

            }
            else {
                if (v.indexOf('@') == -1) {
                    $("#" + id.replace(/btn/g, "")).val(v);
                } else {
                    $("#DeptId").val(v.substring(0, 36));
                    $("#" + id.replace(/btn/g, "")).val(v.substring(37, v.length - 1));
                }
            }
            try {
                if (typeof (ValueChanged) == "function") {//值发生改变后的事件 ValueChanged
                    ValueChanged(rowobj);
                }
            } catch (ex) {

            }
        }
        else {
            $("#" + id.replace(/btn/g, "")).val(v);
        }
        $("#txt" + id.replace(/btn/g, "")).val(t);
        try {
            if (typeof (TextChanged) == "function" && $("#txt" + id.replace(/btn/g, "")).val() != "") {//文本发生改变后的事件 ValueChanged
                TextChanged(rowobj);
            }
        } catch (ex) {

        }
    }

    function getSelectedTRFDept(v, t) {
        //alert(v);
        //debugger;
        if (v != "") {
            if (typeof (v) == "object") {
                var str = v.join(',');
                $("#" + id.replace(/btn/g, "")).val(str);
                $("#TRF" + id.replace(/btn/g, "")).val(str);
                //YAHOO.util.Connect.asyncRequest('POST', url + "?flag=1&testjson=" + str + "&entity=" + entity, callback);

            }
            else {
                if (v.indexOf('@') == -1) {
                    $("#" + id.replace(/btn/g, "")).val(v);
                    $("#TRF" + id.replace(/btn/g, "")).val(v);
                } else {
                    $("#TRFDeptID").val(v.substring(0, 36));
                    $("#TRF" + id.replace(/btn/g, "")).val(v.substring(37, v.length - 1));
                }
            }
        }
        $("#txt" + id.replace(/btn/g, "")).val(t);
    }
    function getSelectedAndDatposinit(v, t) {
        //alert(v);
        var selectValue = "";
        if (v != "") {
            if (typeof (v) == "object") {
                var str = v.join(',');
                $("#" + id.replace(/btn/g, "")).val(str);
                selectValue = str;
               // YAHOO.util.Connect.asyncRequest('POST', url + "?flag=1&testjson=" + str + "&entity=" + entity, callback);

            }
            else {
                if (v.indexOf('@') == -1) {
                    $("#" + id.replace(/btn/g, "")).val(v);
                    selectValue = v;
                } else {
                    $("#DeptId").val(v.substring(0, 36));
                    $("#" + id.replace(/btn/g, "")).val(v.substring(37, v.length - 1));
                    selectValue = v.substring(37, v.length - 1);
                }
            }
        }
        $("#txt" + id.replace(/btn/g, "")).val(t);
        if (selectValue != "")
        {
            $("#TRFDeptID").val(selectValue);
            $("#TRFDeptName").val(t);
            //getDatPost(selectValue, "#" + id.replace(/btn/g, ""));
            getDatPost(selectValue, "#TRFPostID");
            
        }
    }



    function DatPost_Change(obj) {

        $("#TRFPostName").val(obj.options[obj.options.selectedIndex].text);
        var id = obj.value;
       
        var PostRankName = '';
        if (id != '') {
           // debugger;
            BF.PostRankName.init(id);
            PostRankName = BF.PostRankName.getPostRankName();
            //alert(PostRankName);
           
         }
        $("#PostRankName").val(PostRankName);
    }

    function getDatPost(deptID, ctrlName) {
        var url = "../Extend/AjaxData/jsonlist.aspx?entity=DatPost&condition=DeptID='" + deptID + "'";
        $.get(url, function (d, s) {
            // if (d.indexOf("") == -1) {
            var list = eval("(" + d + ")");
            if (list.total == 0) {
                if (entity != "CrmSubjectManager") {
                    alert("该部门无岗位信息，请先维护部门岗位信息！");
                }
                //parent.parent.closeWin();
            }
            else {
                //var ctrlName = "#PositionID";

                var select = $(ctrlName);
                //select[0].options
                select[0].options.length = 0;
                select[0].options.add(new Option('', ''));

                for (var o in list.rows) {
                    var v = list.rows[o].PostID;
                    var t = list.rows[o].PostName;
                    //alert(t);
                    select[0].options.add(new Option(t, v));
                    //additemtoselect(select,t,v);
                }



            }
            // }
        })
    }
    function additemtoselect(objselect, objitemtext, objitemvalue) {
        var varitem = new Option(objitemtext, objitemvalue);
        objselect.options.add(varitem);
    }
    var responseSuccess = function (res) {
        try {
            var str = res.responseText;
            var obj = eval(str);

            var items = eval("[" + str + "]");
            var userIDs = [], userNames = [];
            for (var q = 0; q < items.length; q++) {
                for (var i = 0; i < items[q].length; i++) {
                    userIDs.push(items[q][i].UserID);
                    userNames.push(items[q][i].UName);
                }
            }
            var left = document.getElementById("lstBoxSubject");
            //left.remove(0);
            var l = left.length;
            for (var x = 0; x < l; x++) {
                left.remove(0);
            }
            for (var j = 0; j < userIDs.length; j++) {
                left.add(new Option(userNames[j], userIDs[j])); //
            }
            //alert(obj.length);
            if (str == "1") {
                alert("数据保存成功");
                if (action == 'insert') {
                    //parent.fnAddRow(instance[0]);
                    parent.ReLoadData();
                } else {
                    parent.ReLoadData();
                    //parent.fnUpdateRow(instance[0]);
                }
                parent.closeWin();
            }
            else {
                showMessage();
                alert(str + "\n" + "数据保存失败!");
            }
        }
        catch (e) {
        }
        finally {
        }
    };
    var responseFailure = function (error) {
        alert("数据错误：" + error.statusText);
    }
    // Create a callback object that defines success and failure
    // handlers, and instructs Connection Manager to use the
    // Flash transport by defining the xdr property and setting
    // it to true.
    var callback = {
        success: responseSuccess,
        failure: responseFailure
    };
    function test(v, t) {
        alert("1");
    }
}

//将document.ready中的选择职员代码移至方法中
var rowobj = null; //当前行对像
var SelectEmployee = function (obj) {
    //debugger;
    rowobj = $(obj).parent("td").parent("tr");
    $("button").click(function (event) {
        if (event.target.id.indexOf("btn") > -1) {
            id = event.target.id;
            var name = event.target.name;
            var entityName;
            switch (name.toLowerCase()) {
                case "emp": //选择职员
                    //用户选择
                    entityName = "V_hrEmployee";
                    condition = "";
                    postUrl(entityName, condition, "ID", "CName");
                    break;
                case "in": //发票申请单中选择产品
                    //debugger
                    entityName = "V_CrmCustomerInfoOrderProduct";
                    var orderId = $("#OrderID").val();
                    condition = "ID='" + orderId + "'";
                    src = getUrl + "ChooseList.aspx?r=" + Math.random() + "&kid=OrderProductId&kname=ProductName&entity=" + entityName + "&condition=" + decodeURI(condition) + "";
                    parent.ShowDialog(getSelected, id, src);
                    break;
              
            }
        }
    });
}